package listbyorder.access101_200.test155;

import java.util.Stack;

/**
 * @author code_yc
 * @version 1.0
 * @date 2020/6/13 13:00
 */
public class Solution1 {

    class MinStack {
        Stack<Integer> data;
        Stack<Integer> min;

        public MinStack() {
            data = new Stack<>();
            min = new Stack<>();
        }

        public void push(int x) {
            if (min.isEmpty() || min.peek() >= x) {
                min.push(x);
            }
            data.push(x);
        }

        public int pop() {
            if (data.isEmpty()) {
                throw new RuntimeException("栈空");
            }
            int res = data.pop();
            if (min.peek() == res) {
                min.pop();
            }
            return res;
        }

        public int top() {
            if (data.isEmpty()) {
                throw new RuntimeException("栈空");
            }
            return data.peek();
        }

        public int getMin() {
            if (min.isEmpty()) {
                throw new RuntimeException("栈空");
            }
            return min.peek();
        }
    }
}
